﻿using System;
using System.Web.UI.WebControls;
using BLL;
using Model;

public partial class ProductAirtightness_AirtightnessView_AirtightnessViewbyPIDDT : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindCustoms();
            BindProductTypes();
        }
    }

    protected void BindCustoms()
    {
        Customer cust = new Customer();
        this.DropDownList1.DataSource = cust.LoadEntities();
        this.DropDownList1.DataTextField = "CustomerName";
        this.DropDownList1.DataValueField = "CustomerID";
        this.DropDownList1.DataBind();
    }

    protected void BindProductTypes()
    {
        ProductType pt = new ProductType();
        this.DropDownList2.DataSource = pt.GetProductTypesbyCustomerID(this.DropDownList1.SelectedValue);
        this.DropDownList2.DataTextField = "ProductTypeName";
        this.DropDownList2.DataValueField = "ProductTypeID";
        this.DropDownList2.DataBind();
    }

    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        BindProductTypes();
    }

    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        this.GridView1.PageIndex = e.NewPageIndex;
        BindTests();
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        BindTests();
    }

    private void BindTests()
    {
        DateTime dt1 = DateTime.Parse(this.TextBox1.Value.Trim());
        DateTime dt2 = DateTime.Parse(this.TextBox2.Value.Trim());
        string var_productTypeID = this.DropDownList2.SelectedValue;

        Airtightness a = new Airtightness();
        GridView1.DataSource = a.Airtightness_SelectbyPIDDT(var_productTypeID, dt1, dt2);
        GridView1.DataBind();
        for (int i = 0; i < this.GridView1.Rows.Count; i++)
        {
            if (bool.Parse(GridView1.DataKeys[i].Values[0].ToString()))
            {
                this.GridView1.Rows[i].Cells[5].Text = "Pass";
            }
            else
            {
                this.GridView1.Rows[i].Cells[5].Text = "Fail";
                this.GridView1.Rows[i].Cells[5].ForeColor = System.Drawing.Color.Red;
            }
        }
    }
}
